In the previous recipe, we got the Arduino's on-board LED to flash. In this recipe, we attach an external LED and get it to flash.
This illustrates the key concept of driving digital outputs on the Arduino.
You will need:
Wire up the circuit as follows:
Copy the code below and overwrite the code in the Arduino IDE.
// Constants const int LEDPIN = 9; // Setup is run once void setup() { // Tell Arduino which pins are input and output pinMode(LEDPIN, OUTPUT); } // Loop is run over and over again void loop() { // Flash the LED digitalWrite(LEDPIN,HIGH); delay(1000); digitalWrite(LEDPIN,LOW); delay(1000); }
Now upload the code to the Arduino.
The LED should start flashing.
This code is very similar to the code we used for the built-in LED sketch, but in this case we have defined the specific Arduino pin we have attached the LED to (pin 9).